/*
 * @描述: 
 * @创建者: kilomChou
 * @Date: 2021-04-11 18:00:58
 * @最后编辑: kilomChou
 * @LastEditTime: 2021-10-27 16:55:25
 */

import { _decorator, Component, EditBox } from 'cc';
import { GameApp } from '../GameApp';
const { ccclass, property } = _decorator;

/** 菜单场景 */
@ccclass('MenuMgr')
export class MenuMgr extends Component {

    @property(EditBox)
    inputIp: EditBox
    @property(EditBox)
    inputName: EditBox

    onLoad() {
        GameApp.init();
    }

    start() {
        this.inputIp.string = window.location.host;
    }

    update(dt: number) {

    }

    onClick(e: TouchEvent, data: string) {
        if (GameApp.isInited && !GameApp.starting) {
            switch (data) {
                case "local":
                    GameApp.startLocal(this.getName());
                    break;
                case "remote":
                    let ip = "ws:" + this.inputIp.string;
                    GameApp.startRemote(this.getName(), ip);
                    break;
            }
        }
    }

    getName() {
        return this.inputName.string || "贪吃蛇";
    }
}